package org.budo.support.service;

import java.util.List;

import org.budo.support.dao.IDao;
import org.budo.support.dao.page.Page;

/**
 * @author limingwei2
 */
public class AbstractService<Entity, Id> {
    protected IDao<Entity, Id> getDao() {
        throw new RuntimeException("请在 " + this.getClass().getName() + " 类中覆盖 getDao 方法");
    }

    public Integer deleteByIds(Id[] ids) {
        return this.getDao().deleteByIds(ids);
    }

    public Id insertIgnoreNull(Entity entity) {
        return this.getDao().insertIgnoreNull(entity);
    }

    public Id[] insertBatch(List<Entity> list) {
        return this.getDao().insertBatch(list);
    }

    public Boolean saveBatch(List<Entity> list) {
        return this.getDao().saveBatch(list);
    }

    public Id insert(Entity entity) {
        return this.getDao().insert(entity);
    }

    public Boolean save(Entity entity) {
        return this.getDao().save(entity);
    }

    public Boolean update(Entity entity) {
        return this.getDao().update(entity);
    }

    public Boolean saveIgnoreNull(Entity entity) {
        return this.getDao().saveIgnoreNull(entity);
    }

    public Boolean updateIgnoreNull(Entity entity) {
        return this.getDao().updateIgnoreNull(entity);
    }

    public Boolean deleteById(Id id) {
        return this.getDao().deleteById(id);
    }

    public Entity findById(Id id) {
        return this.getDao().findById(id);
    }

    public Entity findByExample(Entity example) {
        return this.getDao().findByExample(example);
    }

    public List<Entity> listByIds(Id[] ids) {
        return this.getDao().listByIds(ids);
    }

    public List<Entity> list(Page page) {
        return this.getDao().list(page);
    }
}